document.addEventListener("DOMContentLoaded", function () {
    //fetch hostlist from '/post/hotlist'
    fetch('/post/hotlist')
        .then(response => response.json())
        .then(data => {
            console.log(data);
            //get the container element
            const container = document.getElementById('hotlist-container');
            container.innerHTML = '';
            //insert the data into the container
            data.forEach(post => {
                let li = document.createElement('li');
                li.innerHTML = `<a href="/post/view/${post.slug}">${post.title}</a>&nbsp;${post.views} views`;
                container.appendChild(li);
            })
        })
        .catch(error => console.error(error));
});